;; (function () {


  // 登录的帐号密码 验证

  var alogin = $(".login_value");
  var loginpassword = $(".login_password");
  var span = document.querySelector(".span_content");
  var span2 = document.querySelector(".span_content2");
  var inputborder = document.querySelectorAll(".l_c_left_a_c");
  var TEL_REGEXP = /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/;
  var re = /^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/;
  // 密码
  var patrn = /^(\w){6,20}$/;

  function verification() {
    var loginvalue = document.querySelector(".login_value").value;
    if (loginvalue === "") {
      span.innerHTML = "登录名不能为空";
      alogin.focus();
      span.style.display = "block";
      inputborder[0].style.borderColor = "red";
      return false;
    }
    if (typeof Number(loginvalue) === "number" && !TEL_REGEXP.test(loginvalue)) {
      span.innerHTML = "请输入正确的手机号";
      span.style.display = "block";
      alogin.focus();
      inputborder[0].style.borderColor = "red";
      return false;
    }
    if (!re.test(loginvalue) && loginvalue.length != 11) {
      span.innerHTML = "请输入正确的邮箱";
      span.style.display = "block";
      alogin.focus();
      inputborder[0].style.borderColor = "red";
      return false;
    } else {
      span.style.display = "none";
      inputborder[0].style.borderColor = "#dadada";
      return true;
    }
  }
  // 密码的验证
  function verification2() {
    var loginpasswordv = document.querySelector(".login_password").value;

    if (!patrn.test(loginpasswordv)) {
      span2.innerHTML = "请输入6-20个字母、数字、下划线 的密码";
      span2.style.display = "block";
      loginpassword.focus();
      inputborder[1].style.borderColor = "red";
      return false;
    } else {
      span2.style.display = "none";
      inputborder[1].style.borderColor = "#dadada";
      return true;
    }
  }
  alogin.on("blur", verification);
  loginpassword.on("blur", verification2);

  // 登录
  // 设置xhrget
  function xhrGet(url, data) {
    return new Promise((resolve, reject) => {
      var xhr = new XMLHttpRequest();
      if (typeof data !== "function" && data instanceof Object) {
        // 拼接字符串; 
        var _arr = [];
        for (var key in data) {
          _arr.push(`${key}=${data[key]}`)
        }
        var _symbol = /\?/.test(url) ? "&" : "?";
        url += _symbol + _arr.join("&")
      }
      xhr.open("GET", url);
      xhr.send(null);
      xhr.onreadystatechange = function () {
        if (xhr.readyState === 4 && xhr.status === 200)
          resolve(xhr.responseText);
      }
    })
  }

  // 登录

  var username = document.getElementById("usename");
  
  var passwordbtn = document.getElementById("password");
  var loginbtn = document.getElementById("loginbtn");
  console.log(username,password,loginbtn);
  loginbtn.onclick = function () {
    var uservalue = username.value;
    var psdvalue = passwordbtn.value;
    console.log(uservalue, psdvalue);
    xhrGet("http://zhaoyx0907.com/users/login.do", { username: uservalue, password: psdvalue })
      .then(res => {
        console.log(res);
        if (res === "1") {
          alert("登录失败，用户名不存在");
          location.href = "./login.html";
        }
      })
  }
  // 
})()